package io.yunho.yunho.interview.two.thread;

import java.util.Random;
import java.util.concurrent.*;

/**
 * @author: yunho
 * @date: 2021/11/24 18:05
 * @description:
 */
public class TestScheduledTestDemo {
    public static void main(String[] args) throws Exception {
        //初始化调度线程池
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(5);

        for (int i = 0; i < 5; i++) {
            Future<Integer> result = pool.schedule(new Callable<Integer>(){

                @Override
                public Integer call() throws Exception {
                    int num = new Random().nextInt(100);//生成随机数
                    System.out.println(Thread.currentThread().getName() + " : " + num);
                    return num;
                }

            }, 1, TimeUnit.SECONDS);

            System.out.println(result.get());
        }

        pool.shutdown();
    }
}
